<?php 
    function treeview(){
        include("adodb/adodb5/adodb.inc.php");
        $db = NewADOConnection('mysql');
        $db->Connect("localhost", "root", "", "quanly");
          
        $html = ' <div class="css-treeview"><ul>';
        $html .='<li><input type="checkbox" id="item-0" /><label for="item-0">Quản lý điểm cấp</label>';
        $html .='<ul>';
        //----- năm học --------------------
        $sql = "SELECT * FROM namhoc";
        $arr = $db->GetArray($sql);
        
        foreach($arr as $value){
            
            //----- Khối học
            $sql1 ="SELECT * FROM khoi WHERE id_namhoc=".$value['id'];
            $arr1 = $db->Execute($sql1);
            
            $html .='<li><input type="checkbox" id="item-0" /><label for="item-0">'.$value['ten'].'</label>';
            
            $html .='<ul>';
            foreach($arr1 as $value1){
                //-------- Lớp học
                $sql2 = "SELECT * FROM lop WHERE id_khoi=".$value1['id'];
                $arr2 = $db->Execute($sql2);
                
                 $html .='<li><input type="checkbox" id="item-0" /><label for="item-0">'.$value1['ten'].'</label>';
                
                $html .='<ul>';
                foreach($arr2 as $value2){
                    $st = "SELECT monhoc.ten AS ten, monhoc.id AS id,monhoc.id_khoi AS id_khoi FROM monhoc 
                            LEFT JOIN khoi ON khoi.id=monhoc.id_khoi 
                            WHERE khoi.id=".$value1['id'];
                    $info = $db->GetArray($st);
                    //print_r($info);
                    $html .='<li><input type="checkbox" id="item-0" /><label for="item-0">'.$value2['ten'].'</label>';
                    $html .= '<ul>';
                        foreach($info as $info1){
                            $html .='<li><a href="?m=qldiem&act=listall&idnam='.$value['id'].'&idkhoi='.$value1['id'].'&idlop='.$value2['id'].'&id_mon='.$info1['id'].'">'.$info1['ten'].'</a></li>';
                        }
                    $html .='</ul></li>';
                    
                }
                $html .='</ul></li>';
                
            }
            $html .='</ul>';
            $html .='</li>';
        }
        
        $html .='</ul>';
        $html .='</div>';
        
        //--------------------------------------------------------------
        $html .= ' <div class="css-treeview"><ul>';
            $html .='<li><input type="checkbox" id="item-0" /><label for="item-0">Quản lý môn học</label>';
            
            $str = "SELECT * FROM namhoc";
            $data = $db->GetArray($str);
            $html .='<ul>';
            foreach($data as $dt){
                //----- Khối học
                $str1 ="SELECT * FROM khoi WHERE id_namhoc=".$dt['id'];
                $data1 = $db->Execute($str1);
                
                $html .='<li><input type="checkbox" id="item-0" /><label for="item-0">'.$dt['ten'].'</label>';
                
                $html .='<ul>';
                foreach($data1 as $dt1){
                    //-------- Lớp học
                        $html .='<li><a href="?m=qlmon&act=listall&idnam='.$dt['id'].'&idkhoi='.$dt1['id'].'">'.$dt1['ten'].'</a></li>';
                }
                $html .='</ul>';
                $html .='</li>';
            }
            $html .='</ul>';
        $html .='</ul></div>';
        //---------------------------------------------------
        $html .= ' <div class="css-treeview"><ul>';
            $html .='<li><input type="checkbox" id="item-0" /><label for="item-0">Quản lý học sinh</label>';
            $html .='<ul>';
            $strx = "SELECT * FROM namhoc";
            $datax = $db->GetArray($strx);
        
            foreach($datax as $dtx){
                
                //----- Khối học
                $strx ="SELECT * FROM khoi WHERE id_namhoc=".$dtx['id'];
                $datx = $db->Execute($strx);
                
                $html .='<li><input type="checkbox" id="item-0" /><label for="item-0">'.$dtx['ten'].'</label>';
                $html .='<ul>';
                foreach($datx as $dtxx){
                    //-------- Lớp học
                    $sq = "SELECT * FROM lop WHERE id_khoi=".$dtxx['id'];
                    $dtxxx = $db->Execute($sq);  
                    $html .='<li><input type="checkbox" id="item-0" /><label for="item-0">'.$dtxx['ten'].'</label>';
                    $html .='<ul>';
                    foreach($dtxxx as $vls){
                        $html .='<li><a href="?m=qlhs&act=listall&idnam='.$dtx['id'].'&idkhoi='.$dtxx['id'].'&idlop='.$vls['id'].'">'.$vls['ten'].'</a></li>';
                    }
                    $html .='</ul></li>';
                     
                }
                $html .='</ul>';
                $html .='</li>';
            }
            $html .='</ul>';
        $html .='</ul></div>';
        return $html;
    }
    function selectGT($selected = false)
    {
    	$arr = array('Nam','nu');
    	$html = '<select id="gender" name="gender" class="select" title="Select"><option value="">Select</option>';
    	foreach($arr as $values){
    		if($values == $selected  ){
    			$html .= '<option value="'.$values.'" selected="selected">'.ucfirst($values).'</option>';
    		}
    		else{
    			$html .= '<option value="'.$values.'">'.ucfirst($values).'</option>';
    		}
    	}
    	$html .= '</select>';
    	return $html;
    }
    function uploadFile($file,$url,$allowType=array(),$maxSize=1000000){
        $fName=$file['name'];// $_FILES['txtFile']['name']
        $tmpfName=$file['tmp_name'];
        $fSize=$file['size'];
        $ext=getExt($fName);
        if($fSize>$maxSize){
            return 'false';
        }
        if(!in_array($ext,$allowType)){
            return 'false';
        }
        //rename file
        $fName=date('d-m-y-h-i-s').'_'.$fName;
        if(move_uploaded_file($tmpfName, $url.$fName)){
            return $fName;
        }
    }
   function pagenav($base_url, $start, $max_value, $num_per_page) {
    	$pgcont = 4;
    	$pgcont = (int) ($pgcont - ($pgcont % 2)) / 2;
    	if ($start >= $max_value)
    	$start = max(0, (int) $max_value - (((int) $max_value % (int) $num_per_page) == 0 ? $num_per_page : ((int) $max_value % (int) $num_per_page)));
    	else
    	$start = max(0, (int) $start - ((int) $start % (int) $num_per_page));
    	$base_link = '<a class="navpg" href="' . strtr($base_url, array('%' => '%%')) . 'start=%d' . '">%s</a> ';
    	$pageindex = $start == 0 ? '' : sprintf($base_link, $start - $num_per_page, '&lt;');
    	if ($start > $num_per_page * $pgcont)
    	$pageindex .= sprintf($base_link, 0, '1');
    	if ($start > $num_per_page * ($pgcont + 1))
    	$pageindex .= '<span style="font-weight: bold;"> ... </span>';
    	for ($nCont = $pgcont; $nCont >= 1; $nCont--)
    	if ($start >= $num_per_page * $nCont) {
    	$tmpStart = $start - $num_per_page * $nCont;
    	$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
    	}
    	$pageindex .= '<span class="pager">' . ($start / $num_per_page + 1) . '</span>] ';
    	$tmpMaxPages = (int) (($max_value - 1) / $num_per_page) * $num_per_page;
    	for ($nCont = 1; $nCont <= $pgcont; $nCont++)
    	if ($start + $num_per_page * $nCont <= $tmpMaxPages) {
    	$tmpStart = $start + $num_per_page * $nCont;
    	$pageindex .= sprintf($base_link, $tmpStart, $tmpStart / $num_per_page + 1);
    	}
    	if ($start + $num_per_page * ($pgcont + 1) < $tmpMaxPages)
    	$pageindex .= '<span style="font-weight: bold;"> ... </span>';
    	if ($start + $num_per_page * $pgcont < $tmpMaxPages)
    	$pageindex .= sprintf($base_link, $tmpMaxPages, $tmpMaxPages / $num_per_page + 1);
    	if ($start + $num_per_page < $max_value) {
    	$display_page = ($start + $num_per_page) > $max_value ? $max_value : ($start + $num_per_page);
    	$pageindex .= sprintf($base_link, $display_page, '&gt;');
	}
	return $pageindex;
}
?>